package com.cskaoyan.controller;

import com.cskaoyan.bean.ReplyVo;
import com.cskaoyan.bean.StudentBo;
import com.cskaoyan.bean.UserVo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

/**
 * @Aurhor: 11437
 * @DATE: 2022/10/7 19:59
 * @Description:
 * @Version 1.0
 */
@RestController
public class UserController {


    @RequestMapping("say")

    public String test() {


        return "hello";
    }

    @RequestMapping("user/register1")
    public ReplyVo test1(String username, String password, Date birthday) {


        String s = "username:" + username + ";password:" + password + ";birthday:" + birthday;
        System.out.println(s);
        return ReplyVo.ok(s);
    }

    @RequestMapping("user/register2")
    public ReplyVo test2(String username, String password, Date birthday, String[] nickname, Integer[] age) {

        System.out.println(username);
        System.out.println(Arrays.toString(age));

        return ReplyVo.ok(null);
    }

    @RequestMapping("file")
    public ReplyVo test3(MultipartFile myfile) throws IOException {

        String name = myfile.getName();
        String contentType = myfile.getContentType();
        String originalFilename = myfile.getOriginalFilename();
        long size = myfile.getSize();

        File file = new File("C:\\Users\\11437\\Desktop\\image1", "aotoman.jpg");
        myfile.transferTo(file);
        return ReplyVo.ok(null);


    }

    @RequestMapping("files")
    public ReplyVo test3(MultipartFile[] myfiles) throws IOException {

        for (MultipartFile myfile : myfiles) {

            myfile.transferTo(new File("C:\\Users\\11437\\Desktop\\image1",
                    myfile.getOriginalFilename()));

        }
        return ReplyVo.ok(null);


    }

    @RequestMapping("user/test4")
    public ReplyVo test4(UserVo userVo, String like) {

        System.out.println(userVo + like);


        return ReplyVo.ok(null);
    }

    @RequestMapping("user/test5")
    public ReplyVo test5(@RequestBody String jsonstr) {

        System.out.println(jsonstr);

        return ReplyVo.ok(null);

    }


    @RequestMapping("user/test6")
    public ReplyVo test6(@RequestBody StudentBo studentBo) {

        System.out.println(studentBo);
        return ReplyVo.ok(null);

    }


    @RequestMapping("user/test7")
    public ReplyVo test7(@RequestBody Map map) {

        System.out.println(map);
        return ReplyVo.ok(null);

    }

    @RequestMapping("user/test8")
    public ReplyVo test8(HttpServletRequest request) {

        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {

            System.out.println(cookie);
        }
        return ReplyVo.ok(null);

    }

}